Scripting Reference/Physics
Setting the gravity The gravity force isn't a property of each body, it's global, so you can set it using CraftStudio.Physics.SetGravity Physics:SetBodyType Physics:SetBodyType( Physics.BodyType body type ) Sets up the body's type. Possible values: *'Physics.BodyType.Dynamic' - Dynamic bodies are affected by forces (including gravity) and can be moved around *'Physics.BodyType.Static' - Static bodies can't be moved and aren't affected by gravity, useful for scenery *'Physics.BodyType.Kinematic' - Kinematic bodies can be moved programmatically but aren't affected by forces (useful for moving obstacles) Physics:SetupAsBox, Physics:SetupAsSphere, Physics:SetupAsCapsule, Physics:SetupAsMap Physics:SetupAsBox( Vector3 size ) Physics:SetupAsSphere( number radius ) Physics:SetupAsCapsule( number radius, number height ) Physics:SetupAsMap( Map map, TileSet tileSet=nil ) Sets up the body's shape. Physics:SetMass Physics:SetMass( number mass ) Sets the body's mass. Only makes sense on Dynamic 'bodies. Physics:ApplyForce, Physics:ApplyImpulse Physics:ApplyForce( Vector3 force, Vector3 relative position=nil ) Physics:ApplyImpulse( Vector3 impulse, Vector3 relative position=nil ) Applies the specified force or impulse on the body. If ''relative position is nil, then a central force / impulse is applied by default. A force modifies the body's acceleration (which in turns affects the object's velocity over time). An impulse modifies the body's velocity directly. Only works on '''Dynamic bodies. Physics:ApplyTorque, Physics:ApplyTorqueImpulse Physics:ApplyTorque( Vector3 torque ) Physics:ApplyTorqueImpulse( Vector3 impulse ) Applies the specified torque or torque impulse on the body. If relative position is nil, then a central force / impulse is applied by default. A torque modifies the body's angular acceleration (which in turns affects the object's angular velocity over time). An impulse modifies the body's angular velocity directly. Only works on Dynamic bodies. Physics:WarpPosition, Physics:OffsetPosition Physics:WarpPosition( Vector3 position ) Physics:OffsetPosition( Vector3 offset ) Teleports or offsets the body to/by the specified position/offset. Especially useful for moving around kinematic bodies (moving platforms in a platformer, opening doors & so on) Works on Dynamic and Kinematic bodies. (Physics:WarpPosition was previously called Physics:Teleport but has been renamed for consistency) Physics:WarpEulerAngles / Physics:WarpOrientation / Physics:OffsetEulerAngles / Physics:OffsetOrientation Physics:WarpEulerAngles( Vector3 euler Angles ) Physics:WarpOrientation( Quaternion orientation ) Physics:OffsetEulerAngles( Vector3 euler Angles offset ) Physics:OffsetOrientation( Quaternion orientation offset ) WarpEulerAngles / WarpOrientation sets the object's orientation. OffsetEulerAngles / OffsetOrientation applies the specified Euler angles / orientation as an offset to its current orientation. Works on Dynamic and Kinematic bodies. Physics:GetLinearVelocity, Physics:SetLinearVelocity Vector3 Physics:GetLinearVelocity() Physics:SetLinearVelocity( Vector3 velocity ) Returns or sets the body's linear velocity. Only makes sense on Dynamic bodies. Physics:GetAngularVelocity, Physics:SetAngularVelocity Vector3 Physics:GetAngularVelocity() Physics:SetAngularVelocity( Vector3 velocity ) Returns or sets the body's angular velocity. Only makes sense on Dynamic '''bodies. Physics:SetFreezePosition, Physics:SetFreezeRotation Physics:SetFreezePosition( boolean x, boolean y, boolean z ) Physics:SetFreezeRotation( boolean x, boolean y, boolean z ) Sets whether object's position / orientation is fixed around each axis. Only makes sense on '''Dynamic bodies. Example: Freezing an object's rotation entirely self.gameObject.physics:SetFreezeRotation( true, true, true ) Physics:GetFriction, Physics:SetFriction number Physics:GetFriction() Physics:SetFriction( number factor ) Returns or sets the body's friction as a number, 0 being no friction (very slippery) and 1 being high friction (very sticky). Default friction value for newly-created bodies is 1. Physics:GetAnisotropicFriction, Physics:SetAnisotropicFriction Vector3 Physics:GetAnisotropicFriction() Physics:SetAnisotropicFriction( Vector3 friction ) Returns or sets the body's anisotropic friction. Anisotropic basically means "not the same on all axes". By default, anisotropic friction is disabled (friction is the same on all axes). Example: No vertical friction -- Sets the overall friction coefficient self.gameObject.physics:SetFriction( 0.5 ) -- Disable friction on the Y axis (vertically) self.gameObject.physics:SetAnisotropicFriction( Vector3:New( 1, 0, 1 ) )